﻿var xmlHttp_Resource;
function InitPage()
{
    Onload();
    GetAllResource(0,null);
}
function GetAllResource(page,str) 
{ 
   GetXmlHttpObject3();
   var url;
   url = "AllResource.aspx?page="+page+"&"+str;
   xmlHttp_Resource.open("post",url,true);
   xmlHttp_Resource.onreadystatechange=onResource;
   xmlHttp_Resource.send(null); 
}
function onResource()
{
     if (xmlHttp_Resource.readyState == 4) 
     {  
       document.getElementById("AllResource").innerHTML=xmlHttp_Resource.responseText;
     }
}

function GetXmlHttpObject3()
{
  try
    {
     xmlHttp_Resource=new XMLHttpRequest();
    }
  catch (e)
    {
    try
      {
       xmlHttp_Resource=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
       xmlHttp_Resource=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
}
function GetListByType(type)
{
    GetXmlHttpObject3();
   var url = "AllResource.aspx?filetype="+type;
   xmlHttp_Resource.open("post",url,true);
   xmlHttp_Resource.onreadystatechange=onResource;
   xmlHttp_Resource.send(null);
}
function JuniorSearch()
{
    GetXmlHttpObject3();
   var common = document.getElementById("SearchBox").value;
   if(common == "")
    {
        alert("请输入待搜索内容！");
        return;
    }
   var url = "AllResource.aspx?common="+common;
   xmlHttp_Resource.open("post",url,true);
   xmlHttp_Resource.onreadystatechange=onResource;
   xmlHttp_Resource.send(null);
   document.getElementById("SearchBox").value = "";
}
function SeniorShow()
{
    SetTimeSelect();
    var SearchForm = document.getElementById("SeniorSearch");
    var SearchList = document.getElementById("AllResource");
   if(SearchForm.style.display == "block") 
        SearchForm.style.display = "none";
   else
    SearchForm.style.display = "block";
    
    if(SearchList.style.display == "block") 
        SearchList.style.display = "none";
   else
    SearchList.style.display = "block";   
}
function SeniorSearch()
{
    var strpost = GetForm();
    alert(strpost);
    GetAllResource(0,strpost);
    var SearchForm = document.getElementById("SeniorSearch");
    var SearchList = document.getElementById("AllResource");
    SearchForm.style.display = "none";
    SearchList.style.display = "block";
}
function GetForm()
{
    var poststr="";
    var tmp;
    var str="";
    var flag=0;
    var i;
    for(i=0;i<7;i++)
    {
        switch(i)
        {
            case 0:str="title";break;
            case 1:str="keyword";break;
            case 2:str="source";break;
            case 3:str="author";break;
            case 4:str="publisherID";break;
            case 5:str="subject";break;
            case 6:str="filetype";break;
        }
       tmp = document.getElementById(str).value;
       if(tmp != "")
       {
            if(poststr == "")
            {
                poststr += str +"="+ tmp;
            }
            else
            {
                poststr += "&"+str+"="+tmp;
            }          
            flag ++;
        }
    }
    if(flag < 2)
    alert("请输入待查询内容！");
   // else
   var tmp1 = document.getElementById("ybegain").value;
   var tmp2 = mbegain = document.getElementById("mbegain").value;
   var timebegain = tmp1+"-"+tmp2+"-1";
        tmp1 = document.getElementById("yend").value;
        tmp2 = document.getElementById("mend").value;
    var timeend = tmp1+"-"+tmp2+"-1";
    poststr += "&timefrom="+ timebegain;
    poststr += "&timeto=" + timeend;
    return poststr;
}

function SetTimeSelect()
{
    var ybegain = document.getElementById("ybegain");
    var yend = document.getElementById("yend");
    var mbegain = document.getElementById("mbegain");
    var mend = document.getElementById("mend");
     if (ybegain.length<=0)
     {
      for(var j=2010;j<=2030;j++)
        {
         var the_option= new Option(j,j);
         ybegain.add(the_option);
        }
     ybegain.selectedIndex = 0;
    }
    
     if (mbegain.length<=0)
     {
      for(var j=1;j<=12;j++)
        {
         var the_option= new Option(j,j);
         mbegain.add(the_option);
        }
     mbegain.selectedIndex = 0;
    }
    if (yend.length<=0)
     {
      for(var j=2010;j<=2030;j++)
        {
         var the_option= new Option(j,j);
         yend.add(the_option);
        }
     yend.selectedIndex = 0;
    }
    
     if (mend.length<=0)
     {
      for(var j=1;j<=12;j++)
        {
         var the_option= new Option(j,j);
         mend.add(the_option);
        }
     mend.selectedIndex = 0;
    }
}
function SetEndYear()
{
    var ybegain = document.getElementById("ybegain").value;
    var yend = document.getElementById("yend");
    yend.selectedIndex = ybegain-2010;
}
function SetEndMonth()
{
    var ybegain = document.getElementById("ybegain").value;
    var mbegain = document.getElementById("mbegain").value;
    var yend = document.getElementById("yend").value;
    var mend = document.getElementById("mend");
    var yyend = document.getElementById("yend");
    if(ybegain == yend)
        mend.selectedIndex = mbegain;
    if(ybegain < yend)
        mend.selectedIndex = 0;
    if(ybegain > yend)
    {
        alert("时间格式错误");
         yyend.selectedIndex = ybegain-2010;
        mend.selectedIndex = mbegain;
    }
}